package com.gin.no_gay_alliance.activity;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.webkit.WebChromeClient;

import com.gin.nga.callback.JsonCallback;
import com.gin.nga.enums.NgaDomain;
import com.gin.nga.method.NukeApi;
import com.gin.nga.response.body.BaseMessageBody;
import com.gin.no_gay_alliance.app.MyApplication;
import com.gin.no_gay_alliance.customview.ContentWebViewClient;
import com.gin.no_gay_alliance.databinding.ActivityPrivilegeListBinding;
import com.gin.no_gay_alliance.exception.RequireParamException;

/**
 * 版面权限
 *
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2023/11/8 16:37
 **/
public class PrivilegeListActivity extends BaseBindingActivity<ActivityPrivilegeListBinding> {
    public static final String FORUM_ID = "forumId";
    private static final String TAG = PrivilegeListActivity.class.getSimpleName();
    private long forumId;


    /**
     * 解析意图
     *
     * @param intent 意图
     */
    @Override
    protected void handleIntent(Intent intent) {
        this.forumId = intent.getLongExtra(FORUM_ID, 0L);
        if (this.forumId == 0L) {
            throw new RequireParamException();
        }
    }

    /**
     * onCreate中的后续操作
     */
    @Override
    protected void onCreate() {
        Log.d(TAG, "onCreate: " + forumId);

        NukeApi.privilegeList(MyApplication.getClient(), this.forumId).async(new JsonCallback<BaseMessageBody>() {
            @Override
            public void onSuccess(BaseMessageBody body) {
                handler.post(() -> b.wb.loadDataWithBaseURL(NgaDomain.cn.domain, body.getMessage(), "text/html", "UTF-8", null));
            }
        });

        b.wb.setWebChromeClient(new WebChromeClient());
        b.wb.setWebViewClient(new ContentWebViewClient(this));
    }

    /**
     * 装载右上角菜单
     *
     * @param menu         菜单
     * @param menuInflater 菜单渲染器
     */
    @Override
    protected void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {

    }


    /**
     * 启动活动
     *
     * @param context 上下文
     * @param forumId 版面id
     */
    public static void startActivity(Context context, long forumId) {
        Intent intent = new Intent(context, PrivilegeListActivity.class);
        intent.putExtra(FORUM_ID, forumId);
        context.startActivity(intent);
    }
}
